<template>
  <song-list
    :add="true"
    :remove="true"
    :loading="false"
    :songList="data"
    :totalCount="Muse_Download.length"
    @onplay="playMusic"
    @onchangePage="changePage"
    @onremove="removeDownload"
    @onadd="onadd"
  ></song-list>
</template>

<script>

const { ipcRenderer } = window.require("electron");

import songList from "../components/songList";



// 引入方法
import music from "../function/music";

export default {
  data() {
    return {
      page: 0,
      Muse_Download: [],
    };
  },
  computed: {
    data() {
      return this.Muse_Download.slice(this.page * 30, this.page * 30 + 30);
    },
  },
  methods: {
    // 添加到本地播放列表
    onadd(e) {
      music.onadd(e,this)
    },
    // 移除下载管理
    removeDownload(e) {
      // 更新缓存
      this.Muse_Download = this.Muse_Download.filter((_) => _.rid !== e.rid);
      // 更新本地
      ipcRenderer.send("setStore", "Muse_Download", this.Muse_Download);
    },

    // 播放按钮点击
    playMusic(e) {
      music.playMusic(e, this);
    },

    // 换页
    changePage(page) {
      this.page = page - 1;
    },
  },
  created() {
    //   从本地获取下载列表
    this.Muse_Download =
      ipcRenderer.sendSync("getStore", "Muse_Download") || [];
  },
  components: {
    songList,
  },
};
</script>

<style lang="scss" scoped>
</style>